/*
 * HTFileNode.java
 *
 * www.bouthier.net
 * 2001
 */

package ht_birds;

import hypertree.AbstractHTNode;

import java.awt.Color;
import java.awt.Image;
import java.awt.Toolkit;
import java.util.HashMap;
import java.util.Iterator;

import dao.BirdVO;

/**
 * The HTFileNode implements an example of HTNode encapsulating a File.
 */
public class HTDBNode extends AbstractHTNode {

	 private String name = null;
	private BirdVO b = null; // the File encapsulated
	private HashMap children = null; // the children of this node

	/* --- Constructor --- */

	/**
	 * Constructor.
	 * 
	 * @param file
	 *            the File encapsulated in this node
	 */
	public HTDBNode(BirdVO bird) {
		b = bird;
		 name = b.getScientific_name();
		children = new HashMap();

	}

	public HTDBNode(String node_name) {
		b = null;
		name = node_name;
		children = new HashMap();

	}
	
	/* --- Tree management --- */

	/**
	 * Add child to the node.
	 * 
	 * @param child
	 *            the HTFileNode to add as a child
	 */
	protected void addChild(HTDBNode child) {
		children.put(child.getName(), child);
	}

	/* --- HTNode --- */

	/**
	 * Returns the children of this node in an Enumeration. If this node is a
	 * file, return a empty Enumeration. Else, return an Enumeration full with
	 * HTFileNode.
	 * 
	 * @return an Iterator containing child values of this node
	 */
	public Iterator children() {
		return this.children.values().iterator();
	}

	/**
	 * Returns true if this node is not a directory.
	 * 
	 * @return <CODE>false</CODE> if this node is a directory; <CODE>true</CODE>
	 *         otherwise
	 */
	public boolean isLeaf() {
		return children.isEmpty();
	}

	/**
	 * Returns the name of the file.
	 * 
	 * @return the name of the file
	 */
	public String getName() {
		return this.name;
	}

	public Color getColor() {
		return new Color(name.hashCode());
	}

	public Image getImage() {
		Image img = null;
		Toolkit tool = Toolkit.getDefaultToolkit();
		if (b != null)
			img = tool.getImage(b.getImageurl());
		else img  = tool.getImage("http://www.myschool.edu/anImage.gif");
		
		return img;
	}
}
